#include "textureMgr.h"
#include <cassert>

cTextureMgr gTexMgr;

void cTextureMgr::PushTex(WCHAR* texpath,string texKey)
{
	m_pDevice9 = GetDevice9();
	TEX pTex;
	if(mapTexs.find(texKey)!=mapTexs.end())
		return;
	HR(D3DXCreateTextureFromFile(m_pDevice9,texpath,&pTex));
	mapTexs.insert(make_pair(texKey,pTex));
}
 TEX cTextureMgr::GetTex(string texname)
{
	assert(mapTexs.find(texname)!=mapTexs.end());
	return mapTexs[texname];
}
void cTextureMgr::EraseTex(string texname)
{
	if(mapTexs.find(texname)!=mapTexs.end())
	{
		mapTexs.erase(texname);
	}
}
void cTextureMgr::Release()
{
	auto itr = mapTexs.begin();
	while(itr!=mapTexs.end())
	{
		SAFE_RELEASE(itr->second);
	}
}

cTextureMgr* GetTextureMgr()
{
	return &gTexMgr;
}